package com.battery.system.service.battery.impl;

import java.util.List;

import com.battery.common.utils.DateUtils;
import com.battery.system.domain.BO.AppUserBO;
import com.battery.system.domain.VO.AppUserVO;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.battery.system.mapper.AppUserMapper;
import com.battery.system.domain.AppUser;
import com.battery.system.service.battery.IAppUserService;
import com.battery.common.core.text.Convert;
import tk.mybatis.mapper.entity.Example;

/**
 * 用户Service业务层处理
 *
 * @author battery
 * @date 2021-01-20
 */
@Service
public class AppUserServiceImpl extends BaseServiceImpl<AppUser> implements IAppUserService {


    @Autowired
    private AppUserMapper appUserMapper;


    /**
     * 查询用户
     *
     * @param id 用户ID
     * @return 用户
     */
    @Override
    public AppUser selectAppUserById(String id) {
        return appUserMapper.selectAppUserById(id);
    }

    /**
     * 查询用户列表
     *
     * @param appUser 用户
     * @return 用户
     */
    @Override
    public List<AppUser> selectAppUserList(AppUser appUser) {
        return appUserMapper.selectAppUserList(appUser);
    }

    /**
     * 新增用户
     *
     * @param appUser 用户
     * @return 结果
     */
    @Override
    public int insertAppUser(AppUser appUser) {
        appUser.setCreateTime(DateUtils.getNowDate());
        return appUserMapper.insertAppUser(appUser);
    }

    /**
     * 修改用户
     *
     * @param appUser 用户
     * @return 结果
     */
    @Override
    public int updateAppUser(AppUser appUser) {
        appUser.setUpdateTime(DateUtils.getNowDate());
        return appUserMapper.updateAppUser(appUser);
    }

    /**
     * 删除用户对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAppUserByIds(String ids) {
        return appUserMapper.deleteAppUserByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户信息
     *
     * @param id 用户ID
     * @return 结果
     */
    @Override
    public int deleteAppUserById(String id) {
        return appUserMapper.deleteAppUserById(id);
    }

    /**
     * 查询租借用户列表
     *
     * @param appUserBO
     * @return
     */
    @Override
    public List<AppUserVO> selectAppUserVOList(AppUserBO appUserBO) {
        return appUserMapper.selectAppUserVOList(appUserBO);
    }


    @Override
    public AppUser selectByOpenId(String openid) {
        Example example = new Example(AppUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("appUserCode", openid);
        return appUserMapper.selectOneByExample(example);
    }

    /**
     * 查询今日新增用户
     *
     * @return
     */
    @Override
    public Long selectCountTodayAdd() {
        return appUserMapper.selectCountTodayAdd();
    }
}
